package com.sample.action;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
/**
 * 角色action
 * @author 深深
 * @version 1.0
 */
import com.sample.action.form.RoleForm;
import com.sample.javabean.Role;
import com.sample.util.Pager;

public class RoleAction extends BaseAction{
	private Role role = new Role();
	private RoleForm roleForm = new RoleForm();
	private Integer role_no;
	private String role_name;
	

	private Pager<Role> pageList;
	
	//构造函数
	public RoleAction() {
		super();
	}

	/**
	 * 添加角色
	 * @return
	 * @throws Exception
	 */
	public String inputRole(){
		return "inputRole";
	}
	public String addRole()throws Exception{
		try{
			if(roleForm!=null){
				role.addRole(roleForm);
			}
			return SUCCESS;
		}catch (Exception e) {
			
			 System.out.println("Action:role_no="+roleForm.getRole_no()+", role_name="+roleForm.getRole_name()+", role_remark="+roleForm.getRole_remark());
			 e.printStackTrace();
			 throw new Exception("添加失败，Exception_Action:<--" + e+"-->");
		}
	}
	
	/**
	 * 删除角色
	 * @return
	 * @throws Exception
	 */
	public String delRole()throws Exception{
		try{
			if(roleForm!=null){
				role.setRole_no(role_no);
				role.delRole();
			}
			return SUCCESS;
		}catch (Exception e) {
			System.out.println("Action:role_no="+roleForm.getRole_no()+", role_name="+roleForm.getRole_name()+", role_remark="+roleForm.getRole_remark());
			e.printStackTrace();
			 throw new Exception("删除失败，Exception_Action:<--" + e+"-->");
		}	
		
	}
	
	/**
	 * 编辑角色信息
	 * @return
	 * @throws Exception
	 */
	public String editRole()throws Exception{
		try{
			role.setRole_no(role_no);
			role.load();
			return "editRole";
		}catch (Exception e) {
			System.out.println("Action:role_no="+role.getRole_no()+", role_name="+role.getRole_name()+", role_remark="+role.getRole_remark());
			e.printStackTrace();
			 throw new Exception("加载角色信息失败，Exception_Action:<--" + e+"-->");
		}	
	}
	/**
	 * 修改角色
	 * @return
	 * @throws Exception
	 */
	
	public String edit()throws Exception{
		try{
			if(roleForm!=null){
			 role.editRole(roleForm);
			}
			return SUCCESS;
		}catch (Exception e) {
			System.out.println("Action:role_no="+roleForm.getRole_no()+", role_name="+roleForm.getRole_name()+", role_remark="+roleForm.getRole_remark());
			e.printStackTrace();
			 throw new Exception("编辑失败，Exception_Action:<--" + e+"-->");
		}	
	}
	/**
	 * 加载角色名
	 * @throws Exception
	 */
	public void loadRole_name()throws Exception{
		try{
			role.setRole_name(role_name);
			role.loadname();
			ActionContext actionContext = ActionContext.getContext();
			Map session = actionContext.getSession();
			session.put("role",this.role);
			
		}catch (Exception e) {
		
			e.printStackTrace();
			 throw new Exception("加载角色信息失败，Exception_Action:<--" + e+"-->");
		}	
	}
	
	/**
	 * 分页显示角色
	 * @return
	 * @throws Exception
	 */
	public String listRole()throws Exception{
		try{
			pageList=role.list(page,size,roleForm);
			return "listRole";
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("分页显示失败，Exception_Action:"+e);
		}
	}
	
	//属性访问方法
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public RoleForm getRoleForm() {
		return roleForm;
	}

	public void setRoleForm(RoleForm roleForm) {
		this.roleForm = roleForm;
	}

	public Integer getRole_no() {
		return role_no;
	}

	public void setRole_no(Integer role_no) {
		this.role_no = role_no;
	}
	
	public String getRole_name() {
		return role_name;
	}

	public void setRole_name(String role_name) {
		this.role_name = role_name;
	}
	public Pager<Role> getPageList() {
		return pageList;
	}

	public void setPageList(Pager<Role> pageList) {
		this.pageList = pageList;
	}
}